package com.xinkao.example.controller;

import com.alibaba.fastjson.JSONObject;
import com.xinkao.example.config.annotation.SysLog;
import com.xinkao.example.service.CommonService;
import com.xinkao.example.service.RoleService;
import com.xinkao.example.util.CommonUtil;
import com.xinkao.example.util.model.MenuModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @author zhoujing
 * @date 2021/3/11 9:15
 * @description 公共类controller
 */
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    @Autowired
    private RoleService roleService;

    @SysLog(module = "公共模块", operate = "获取树形菜单")
    @GetMapping("/getMenuTree")
    public JSONObject getMenuTree() {
        List<MenuModel> list = commonService.getMenuTree(null);
        return CommonUtil.successJson(list);
    }

    /**
     * 查字典
     * @param request
     * @return
     */
    @SysLog(module = "公共模块", operate = "字典列表")
    @GetMapping("/getDictList")
    public JSONObject getDictList(HttpServletRequest request){
        CommonUtil.hasAllRequired(CommonUtil.request2Json(request), "dictKey");
        return commonService.getDictList(CommonUtil.request2Json(request));
    }

    @GetMapping("/getRoleList")
    @SysLog(module = "公共模块", operate = "角色列表")
    public JSONObject getRoleList() {
        return roleService.listRole();
    }
}
